package ua.khpi.si.kit49.diploma.db.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ua.khpi.si.kit49.diploma.db.dto.UserRole;

@Repository("userRoleDAO")
public class UserRoleDAOImpl implements UserRoleDAO {

	private static final String QUERY_GET_USER_ROLE_BY_ID = "FROM UserRole WHERE userRoleId = :id";

	@Autowired(required = true)
	private SessionFactory sessionFactory;

	@Override
	public UserRole getUserRoleById(Integer id) {
		return (UserRole) sessionFactory.getCurrentSession()
				.createQuery(QUERY_GET_USER_ROLE_BY_ID).setParameter("id", id)
				.uniqueResult();
	}

	@Override
	public void saveOrUpdateUserRole(UserRole userRole) {
		sessionFactory.getCurrentSession().saveOrUpdate(userRole);
	}

}
